let Base64 = android.util.Base64;
let KeyFactory = java.security.KeyFactory;
let X509EncodedKeySpec = java.security.spec.X509EncodedKeySpec;
let Cipher = javax.crypto.Cipher;


let base_url = "310898026";

let PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIGcakQhmIK181wjhozfiY6rY5hu7Cb/+YHg3Y25XZKUnCfxlCO6hcj56GN53rf5h8AxKiieRZgxXA+pf8KCpisCAwEAAQ==";

// let bos = new java.io.ByteArrayOutputStream();
// let pubkeybyte = new java.lang.String(PUBLIC_KEY).getBytes('utf-8');
// let str = new java.lang.String(base_url).getBytes('utf-8');
let de =Base64.decode(PUBLIC_KEY, Base64.DEFAULT);
log(de)

//加密
let pubKey =KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(PUBLIC_KEY, Base64.DEFAULT)));
let cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, pubKey)
let dab =cipher.doFinal(java.lang.String(base_url).getBytes("UTF-8"))

let a  =Base64.encodeToString(dab,Base64.DEFAULT);

// log(bdata)
log(a)
// RSA加密
// let message = "未加密字符串";
// log("明文: ", message);

// // 生成RSA密钥
// let keyPair = $crypto.generateKeyPair("RSA");
// log("密钥对: ", keyPair);

// // 使用私钥加密
// let rsa = $base64.encode($crypto.encrypt(message, keyPair.privateKey, "RSA/ECB/PKCS1padding"));
// log("RSA私钥加密后二进制数据: ", rsa);

// 使用公钥解密
// log("RSA公钥解密: ", $crypto.decrypt($base64.decode(rsa), keyPair.publicKey, "RSA/ECB/PKCS1padding", {output: 'string'}));


// var res = http.post("http://192.168.1.5/device/add",{});

// log(res)